package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.common.constant.Constant;
import com.oceansoft.mobile.econsole.modules.api.service.ICityTabService;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.jlwt.entity.SysOrg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by wzy on 2016/1/29.
 */
@RestController
@RequestMapping("api/city")
public class ApiCityTabController {


    @Resource
    private ICityTabService cityTabService;

    //地区
    @RequestMapping(value = "regions", method = RequestMethod.GET)
    public Result getRegion() {
        return  cityTabService.getRegion();
    }

    //分局
    @RequestMapping(value = "substation/{parentGuid}", method = RequestMethod.GET)
    public Result getSubstation(@PathVariable("parentGuid") String parentGuid) {
        return  cityTabService.getSubstation(parentGuid);
    }

    @RequestMapping(value = "cityTab", method = RequestMethod.GET)
    public Result cityTab(HttpServletRequest request){
        String guid = request.getParameter("guid");
        SysOrg sysOrg = cityTabService.findSysOrgById(guid);
        request.getSession().setAttribute(Constant.CURRENT_CITY,sysOrg);
        return new Result(Result.SUCC,sysOrg);
    }

}
